package cn.cqie.frame.controller;

import cn.cqie.frame.bo.LoginBo;
import cn.cqie.frame.service.SysUserService;
import cn.cqie.frame.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 谢一弘
 * @date 2021/9/14  10:56
 */
@Api("登入登出")
@RestController
public class LoginController {
    @Autowired
    private SysUserService sysUserService;

    /**
     * 登录
     * @param bo
     * @return
     */
    @ApiOperation("登录")
    @PostMapping(value = "/login")
    @ResponseBody
    public ResultVo<String> login(@RequestBody LoginBo bo) {
        String token = sysUserService.login(bo);
        return ResultVo.success("", token);
    }

    /**
     * 退出登录
     * @return
     */
    @ApiOperation("登出")
    @GetMapping(value = "/logout")
    public ResultVo<Void> logout() {
        sysUserService.logOut();
        return ResultVo.success("成功");
    }
}
